package com.zrrd.yt.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zrrd.yt.model.user.UserInfo;
import com.zrrd.yt.user.mapper.UserInfoMapper;
import com.zrrd.yt.user.service.UserInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
    @Override
    public UserInfo login(UserInfo userInfo) {
        //获取用户传递过来的密码
        String passwd = userInfo.getPasswd();
        //将密码md5方式加密后重新赋值
        passwd = DigestUtils.md5DigestAsHex(passwd.getBytes());
        //条件查询
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("login_name",userInfo.getLoginName());
        wrapper.eq("passwd",passwd);
        UserInfo user = this.getOne(wrapper);
        //返回
        return user;
    }
}
